package edu.hawaii.jmotif.text;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class TestCosineSimilarity {

  @Test
  public void testCosineSimilarity() {

    WordBag wb1 = new WordBag("first");
    WordBag wb2 = new WordBag("second");

    wb1.addWord("me", 2);
    wb1.addWord("Julie", 1);
    wb1.addWord("likes", 0);
    wb1.addWord("loves", 2);
    wb1.addWord("Jane", 0);
    wb1.addWord("Linda", 1);
    wb1.addWord("than", 1);
    wb1.addWord("more", 1);

    wb2.addWord("me", 2);
    wb2.addWord("Julie", 1);
    wb2.addWord("likes", 1);
    wb2.addWord("loves", 1);
    wb2.addWord("Jane", 1);
    wb2.addWord("Linda", 0);
    wb2.addWord("than", 1);
    wb2.addWord("more", 1);

    double dist = TextUtils.cosineDistance(wb1.getWordsAsDoubles(), wb2.getWordsAsDoubles());

    assertEquals("Testing cosine similarity", 0.822, dist, 0.001);
  }

}
